import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import UserRegister from "../views/UserRegister";
import UserLogin from "../views/UserLogin";
import CourseList from "../views/CourseList";
import CourseDetail from "../views/CourseDetail";
import VideoPlay from "../views/VideoPlay";

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    meta:{
      title:'优学在线教育-首页'
    },
    component: Home
  },
  {
    path: '/foreuser/register/',
    name: 'UserRegister',
    meta:{
      title:'优学在线教育-注册'
    },
    component: UserRegister
  },
  {
    path: '/foreuser/login/',
    name: 'UserLogin',
    meta:{
      title:'优学在线教育-登录'
    },
    component: UserLogin
  },
  {
    path: '/list',
    name: 'CourseListHome',
    meta:{
      title:'优学在线教育-课程列表'
    },
    component: CourseList
  },
  {
    path: '/list-:id',
    name: 'CourseList',
    meta:{
      title:'优学在线教育-课程列表'
    },
    component: CourseList
  },
  {
    path: '/class-:id',
    name: 'CourseDetail',
    meta:{
      title:'优学在线教育-课程详情'
    },
    component: CourseDetail
  },
  {
    path: '/video-:id',
    name: 'VideoPlay',
    meta:{
      title:'优学在线教育-视频播放'
    },
    component: VideoPlay
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
//router的守卫
router.beforeEach((to,from,next)=>{
  document.title=to.meta.title?to.meta.title:"优学在线教育"
  next()
})


export default router
